import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import webExtension from '@samrum/vite-plugin-web-extension'
import path from 'path'
import UnoCSS from 'unocss/vite'
import manifest from './src/manifest'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    UnoCSS(),
    webExtension({
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      manifest: manifest as any,
      useDynamicUrlWebAccessibleResources: false,
    }),
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
    },
  },
  build: {
    target: 'es2019',
    rollupOptions: {
      input: {
        // 确保content script被正确构建
        'content/index': 'src/content/index.ts',
        'background/index': 'src/background/index.ts',
      },
    },
  },
  server: {
    port: 5173,
    strictPort: true,
    hmr: {
      port: 5174,
    },
  },
})
